

using [java] com.orientechnologies.orient.core.db.document::ODatabaseDocumentTx
using [java] com.orientechnologies.orient.core.record.impl::ODocument
using [java] org.juiceshop.orientdb::RecordHelper

class Record
{
  ODocument oDocument { private set }
  
  internal new make(DocDatabase db, Str className, |This|? closure:=null ) {
    oDocument = ODocument(db.oDatabase,className)
    if (closure!=null) closure.call(this)
  }
  
  @Operator
  Obj? get(Str name) {
    oDocument.containsField(name) ? oDocument.field(name) : null
  }
  
  @Operator
  Void set(Str name, Obj? value) {
    if (value==null) {
      oDocument.removeField(name)
    } else {
      Obj nvalue := value
      RecordHelper.setField(oDocument,name,nvalue)
    }
  }
  
  Void setAll(Str:Obj values) {
    values.each |v,k| { set(k,v) }
  }
  
  Void save() { oDocument.save }

  Void delete() { oDocument.delete }
}